package thread;

import javax.swing.*;
import java.lang.Runnable;
import java.util.ArrayList;
import java.util.List;

public class SailTick  extends Thread{
    private List<Ticks> lists;
    private JTextArea ta;

    public SailTick(List<Ticks> lists, JTextArea ta) {
        this.lists = lists;
        this.ta = ta;
    }

    //    public SailTick( int count) {
//
//        lists=new ArrayList<>();
//        for (int i=0;i<count;i++){
//            lists.add(new Ticks(i+1));
//
//        }
//    }
    @Override
    public void run(){
        int c=0;
        while (true){
            Ticks t;
            synchronized (lists){
            if (lists.size()<=0)break;
            t=lists.remove(0);
            c++;
            }
            ta.append(Thread.currentThread().getName()+"卖了"+t+"\n");
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        ta.append(Thread.currentThread().getName()+"卖了"+c+"张！"+"\n");
    }
}
